//
//  WeatherViewController.m
//  SinceLe
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 李元喜. All rights reserved.
//

#import "WeatherViewController.h"

@interface WeatherViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *weatherImageView;

@property (weak, nonatomic) IBOutlet UIImageView *weatherView;
@property (weak, nonatomic) IBOutlet UILabel *currentLable;
@property (weak, nonatomic) IBOutlet UILabel *maxWeatherLable;
@property (weak, nonatomic) IBOutlet UILabel *minWeatherLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *weekLabel;
@property (weak, nonatomic) IBOutlet UILabel *windLabel;
@property (weak, nonatomic) IBOutlet UILabel *weatherType;
@property (weak, nonatomic) IBOutlet UILabel *wenduAlert;
@property (weak, nonatomic) IBOutlet UILabel *ziwaixianAlert;
@property (weak, nonatomic) IBOutlet UILabel *wearAlert;
@property (weak, nonatomic) IBOutlet UILabel *sunCloth;




@end

@implementation WeatherViewController


-(void)setWeatherImg{
    //判断天气类型
    NSString* weatherType = _model.type;
    if ([weatherType isEqualToString:@"晴"]) {
        _weatherView.image =  [UIImage imageNamed:@"day_Sunny"];
        [self setSun];
    }else if ([weatherType isEqualToString:@"多云"]){
        _weatherView.image = [UIImage imageNamed:@"day_Cloudy"];
        [self  setSun];
    }else if ([weatherType isEqualToString:@"阴"]){
        _weatherView.image = [UIImage imageNamed:@"day_Overcast"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"阵雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Shower"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"雷阵雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Thundershower"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"雷阵雨伴有冰雹"]){
        _weatherView.image = [UIImage imageNamed:@"day_Thundershower with hail"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"雨夹雪"]){
        [self setSnow];
        _weatherView.image = [UIImage imageNamed:@"day_Sleet"];
    }else if ([weatherType isEqualToString:@"小雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Light rain"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"中雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Moderate rain"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"大雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Heavy rain"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"暴雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Storm"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"大暴雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_heavy storm"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"特大暴雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Severe storm"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"阵雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Snow flurry"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"小雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Light snow"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"中雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Moderate snow"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"大雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Heavy snow"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"暴雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Snowstorm"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"雾"]){
        _weatherView.image = [UIImage imageNamed:@"day_Foggy"];
        [self setSandStorm];
    }else if ([weatherType isEqualToString:@"冻雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Ice rain"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"沙尘暴"]){
        _weatherView.image = [UIImage imageNamed:@"day_Duststorm"];
        [self setSandStorm];
    }else if ([weatherType isEqualToString:@"小到中雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Light to moderate rain"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"中到大雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Moderate to heavy rain"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"大到暴雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Heavy rain to storm"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"暴雨到大暴雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Storm to heavy storm"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"大暴雨到特大暴雨"]){
        _weatherView.image = [UIImage imageNamed:@"day_Heavy to severe storm"];
        [self setRain];
    }else if ([weatherType isEqualToString:@"小到中雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Light to moderate snow"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"中到大雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Moderate to heavy snow"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"大到暴雪"]){
        _weatherView.image = [UIImage imageNamed:@"day_Heavy to snowstorm"];
        [self setSnow];
    }else if ([weatherType isEqualToString:@"浮尘"]){
        _weatherView.image = [UIImage imageNamed:@"day_Dust"];
        [self setSandStorm];
    }else if ([weatherType isEqualToString:@"扬沙"]){
        _weatherView.image = [UIImage imageNamed:@"day_Sand"];
        [self setSandStorm];
    }else if ([weatherType isEqualToString:@"强沙尘暴"]){
        _weatherView.image = [UIImage imageNamed:@"day_Sandstorm"];
        [self setSandStorm];
    }else if ([weatherType isEqualToString:@"霾"]){
        _weatherView.image = [UIImage imageNamed:@"day_Haze"];
        [self setSandStorm];
    }else{
        _weatherView.image = [UIImage imageNamed:@"day_Unknow"];
        [self setRain];
    }


}

//下雨
-(void)setRain{
    //把tiff加入到数组里
    NSMutableArray* imgArrM = [NSMutableArray array];
    for (int i = 1; i<3 ; i ++) {
        NSString* imgStr = [NSString stringWithFormat:@"rain_%d.tiff",i];
        [imgArrM addObject:[UIImage imageNamed:imgStr]];
    }
    //为_imgView加需要播放的图片数组
    _weatherImageView.animationImages = imgArrM;
    //设置播放的时间
    _weatherImageView.animationDuration = 0.5f;
    //设置播放的次数
    _weatherImageView.animationRepeatCount = 12000;
    //开始播放
    [_weatherImageView startAnimating];

}

//下雪
-(void)setSnow{
    //把tiff加入到数组里
    NSMutableArray* imgArrM = [NSMutableArray array];
    for (int i = 1; i<37 ; i ++) {
        NSString* imgStr = [NSString stringWithFormat:@"snow_%d.tiff",i];
        [imgArrM addObject:[UIImage imageNamed:imgStr]];
    }
    //为_imgView加需要播放的图片数组
    _weatherImageView.animationImages = imgArrM;
    //设置播放的时间
    _weatherImageView.animationDuration = 2.0f;
    //设置播放的次数
    _weatherImageView.animationRepeatCount = 12000;
    //开始播放
    [_weatherImageView startAnimating];

}

//晴天
-(void)setSun{
    //把tiff加入到数组里
    NSMutableArray* imgArrM = [NSMutableArray array];
    for (int i = 1; i<16 ; i ++) {
        NSString* imgStr = [NSString stringWithFormat:@"sun_%d.tiff",i];
        [imgArrM addObject:[UIImage imageNamed:imgStr]];
    }
    //为_imgView加需要播放的图片数组
    _weatherImageView.animationImages = imgArrM;
    //设置播放的时间
    _weatherImageView.animationDuration = 2.0f;
    //设置播放的次数
    _weatherImageView.animationRepeatCount = 12000;
    //开始播放
    [_weatherImageView startAnimating];

}

//沙尘暴
-(void)setSandStorm{
    _weatherImageView.image = [UIImage imageNamed:@"WeatherSand"];
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //判断设置天气图片和背景图片
    [self setWeatherImg];
    //隐藏导航栏
    [self.navigationController.navigationBar setHidden:YES];
    //当前温度
    _currentLable.text = [NSString stringWithFormat:@"当前温度:%@", _model.curTemp];
    //最高温度
    _maxWeatherLable.text = [NSString stringWithFormat:@"最高温度%@", _model.hightemp];
    //最低温度
    _minWeatherLabel.text = [NSString stringWithFormat:@"最低温度%@", _model.lowtemp];
    //城市
    _cityLabel.text = _model.city;
    //日期
    _dateLabel.text = _model.date;
    //风力
    _windLabel.text = [NSString stringWithFormat:@"风力%@", _model.fengli];
    //周
    _weekLabel.text = _model.week;
    //天气类型
    _weatherType.text = _model.type;
    //温馨提醒
    _wenduAlert.text = _model.tempLabel;
    _wearAlert.numberOfLines = 0;
    [_wenduAlert sizeToFit];
    
    _ziwaixianAlert.text = _model.ziwaixianLabel;
    [_ziwaixianAlert sizeToFit];
    
    _wearAlert.text = _model.wearLabel;
    [_wearAlert sizeToFit];
    
    _sunCloth.text = _model.sunClothlabel;
    [_sunCloth sizeToFit];
    
}

//点击屏幕
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (self.navigationController.navigationBar.isHidden == YES) {
        [self.navigationController.navigationBar setHidden:NO];
    }else{
        [self.navigationController.navigationBar setHidden:YES];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"天气详情";
 

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

@end
